home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / contextMenu.js < prev    next >
Encoding:
JavaScript  |  2002-10-03  |  11.3 KB  |  313 lines

  1. /*------------------------------ nsContextMenu ---------------------------------
  2. |   This JavaScript "class" is used to implement the IM standalon's            |
  3. |   content-area context menu.                                                 |
  4. |                                                                              |
  5. |   For usage, see references to this class in contextMenu.xul.                |
  6. |                                                                              |
  7. ------------------------------------------------------------------------------*/
  8. // global context menu
  9. //var contextMenu = null;
  10.  
  11. function nsContextMenu( xulMenu ) {
  12.   this.menu                  = null;
  13.   this.onlineTab        = false;
  14.   this.listSetupTab     = false;
  15.   this.sidebar          = false;
  16.   this.screenName       = "";
  17.   this.target           = null;
  18.  
  19.   // Initialize new menu.
  20.   this.initMenu( xulMenu );
  21. }
  22.  
  23. // Prototype for nsContextMenu "class."
  24. nsContextMenu.prototype = {
  25.  
  26.     // onDestroy is a no-op at this point.
  27.     onDestroy : function () {
  28.     },
  29.  
  30.     // Initialize context menu.
  31.     initMenu : function ( popup, event ) {
  32.         
  33.         this.menu = popup;
  34.  
  35.         // Get contextual info.
  36.         this.setTarget( document.popupNode );
  37.     
  38.         // Initialize (disable/remove) menu items.
  39.         this.initItems();
  40.     },
  41.  
  42.     initItems : function () {
  43.         this.initOnlineItems();
  44.         this.initListSetupItems();
  45.     },
  46.  
  47.     initOnlineItems : function () {
  48.       this.showItem("context-getMemberInfo", this.onlineTab );
  49.       this.showItem( "context-sendIM", this.onlineTab );
  50.       this.showItem( "context-sendChat", this.onlineTab );
  51.       if (this.screenName != "" && this.screenName != null) {
  52.         this.setItemAttr("sendfileseparator","hidden", this.listSetupTab);
  53.         this.showItem( "context-sendFile", this.onlineTab );
  54.         if (aimBuddyIsIcq(this.screenName))
  55.         {
  56.           this.showItem("context-editdispname", true);
  57.         }
  58.         else
  59.         {
  60.           this.showItem("context-editdispname", false);
  61.         }
  62.         var isInList = new Object();
  63.         aimBuddyManager().IsBuddyInAlertList(this.screenName, isInList);
  64.         if ( isInList.value == false ) {
  65.           // Set the appropriate node's screen name to the buddy alert menu item
  66.           this.setItemAttr("context-editbuddyAlert","hidden", "true");
  67.           this.setItemAttr("context-delbuddyAlert","hidden", "true");
  68.           var Msg1=window.document.getElementById("context-buddyAlert").getAttribute("label1");
  69.           var Msg2=window.document.getElementById("context-buddyAlert").getAttribute("label2");
  70.           var newlabel=Msg1+this.screenName+Msg2;
  71.           window.document.getElementById("context-buddyAlert").setAttribute('label', newlabel);
  72.           this.setItemAttr("buddyalertseperator","hidden", "false");
  73.           this.setItemAttr("context-buddyAlert","hidden", "false");
  74.         }
  75.         else {
  76.           // Set the Edit and Del buddy alert menu item
  77.           var Msg1=window.document.getElementById("context-delbuddyAlert").getAttribute("label1");
  78.           var Msg2=window.document.getElementById("context-delbuddyAlert").getAttribute("label2");
  79.           var newlabel=Msg1+this.screenName+Msg2;
  80.           this.setItemAttr("context-buddyAlert","hidden", "true");
  81.           window.document.getElementById("context-delbuddyAlert").setAttribute('label', newlabel);
  82.           this.setItemAttr("context-editbuddyAlert","hidden", "false");
  83.           this.setItemAttr("context-delbuddyAlert","hidden", "false");
  84.         }
  85.       }
  86.       else {
  87.         //selected node has no screen name so it is a group
  88.         this.setItemAttr("sendfileseparator","hidden", "true");
  89.         this.setItemAttr("buddyalertseperator","hidden", "true");
  90.         this.setItemAttr("context-buddyAlert","hidden", "true");
  91.         this.showItem( "context-sendFile", false);
  92.         this.showItem("sendfileseparator", false);
  93.         this.showItem("context-editdispname", false);
  94.         //this.showItem("context-sendemail", false);
  95.         //this.showItem("context-checkemail", false);
  96.         //this.showItem("context-updateemail", false);
  97.         //this.setItemAttr("dispNameseparator","hidden", "true");
  98.         //this.setItemAttr("preemailseperator","hidden", "true");
  99.         //this.setItemAttr("emailseperator","hidden", "true");
  100.         this.setItemAttr("sendfileseparator","hidden", "true");
  101.       }
  102.       
  103.       this.showItem( "onlineseparator", this.onlineTab );
  104.       //this.showItem( "context-EditList", this.sidebar );
  105.     },
  106.  
  107.     initListSetupItems : function () {
  108.         //this.showItem("context-buddyAlert", this.listSetupTab );
  109.         //this.showItem( "context-addBuddy", this.listSetupTab );
  110. //        this.showItem( "context-addGroup", this.listSetupTab );
  111. //        this.showItem( "context-delete", this.listSetupTab );
  112.         //this.showItem( "context-editAB", this.listSetupTab );
  113.       this.setItemAttr("sendfileseparator","hidden", this.listSetupTab);
  114.       this.setItemAttr("dispNameseparator","hidden", this.listSetupTab);
  115.     },
  116.  
  117.     // Set various context menu attributes based on the state of the world.
  118.     setTarget : function ( node ) {
  119.         // Remember the node that was clicked.
  120.         this.target = node;
  121.               var sidebarframe=window; 
  122.           // determine if we're in the standalone or sidebar
  123.         var parentState = top.document.getElementById("AimSidebarState");
  124.         if(!parentState)
  125.         {
  126.             var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  127.             if (tab.selectedIndex == 0 )  
  128.                 {
  129.                 this.sidebar = true;   
  130.                 this.onlineTab = true;
  131.                 this.listSetupTab = false;
  132.                 }        
  133.                        else
  134.                 {
  135.                 this.sidebar = true;   
  136.                                 this.onlineTab = false;
  137.                                 this.listSetupTab = true;  
  138.                 }
  139.         }
  140.         else
  141.         {
  142.               var curTab;
  143.               curTab = parentState.getAttribute("AimSidebarTab");
  144.           // Determine if we're in the Online tab or List Setup tab
  145.               if(curTab == "Online")
  146.                   {
  147.                       this.onlineTab = true;
  148.                       this.listSetupTab  = false;
  149.               this.sidebar = false;
  150.                   }
  151.               else
  152.                   {
  153.                       this.listSetupTab = true;
  154.                       this.onlineTab = false;
  155.               this.sidebar = false;
  156.                   }
  157.           }
  158.  
  159.         // set the screen name based on the target
  160.         //this.screenName = this.target.parentNode.parentNode.getAttribute('ScreenName');
  161.         this.screenName = getSelectedScreenName();
  162.         
  163.     },
  164.  
  165.     // sendIM
  166.     cmdContextSendIM : function () {
  167.       dump("Context: Send IM\n");
  168.     cmdNewIM();
  169. /*      if (aimIMDoesIMExist(this.screenName))
  170.               aimErrorBox(aimString("msg.DuplicateIM"));
  171.           else 
  172.                 aimIMInvokeIMForm(this.screenName);
  173. */
  174.     },
  175.  
  176.     // sendChat
  177.     cmdContextSendChat : function () {
  178.           //window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no','', false,'outgoingchat');
  179.      inviteArgsObj = {
  180.          inviteProposalScreenName: '', 
  181.          inviteProposalObj: null,
  182.          invitedScreenNames: getSelectedBuddiesFromList(),
  183.          inviteToExistingWindow: false,
  184.          inviteMode: 'outgoingchat'
  185.          }
  186.           window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  187.  
  188.  
  189.           dump("Context: Chat\n");
  190.     },
  191.  
  192.     cmdContextSendFile : function () {
  193.      inviteArgsObj = {
  194.          inviteProposalScreenName: getSelectedScreenName(), 
  195.          inviteProposalObj: null,
  196.          inviteToExistingWindow: false,
  197.          inviteMode: 'outgoingfile'
  198.          }
  199.           window.openDialog('chrome://aim/content/sendfile.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  200.     },
  201.  
  202.     cmdContextGetMemberInfo : function () {
  203.       var screenName = getSelectedScreenName();
  204.       window.openDialog('chrome://aim/content/GetMemberInfo.xul','_blank','chrome,all,dialog=no', screenName);
  205.     },
  206.  
  207.     // Edit List
  208.     cmdContextEditList : function  () {
  209.       dump("Context: Edit List\n");
  210.       //toOpenWindowByType2('Aim:AimApp', 'chrome://aim/content/App.xul');
  211.     },
  212.  
  213.     // addbuddy
  214.     cmdContextAddBuddy : function () {
  215.       dump("Context: Add Buddy\n");
  216.       cmdAddBuddy();
  217.     },
  218.  
  219.     // addGroup
  220.     cmdContextAddGroup : function () {
  221.       dump("Context: Add Group\n");
  222.       cmdAddGroup();
  223.     },
  224.  
  225.       // delete
  226.     cmdContextDelete : function () {
  227.       dump("Context: Delete\n");
  228.       cmdDelete();
  229.     },
  230.  
  231.     cmdContextBuddyAlert : function (isedit) {
  232.       var screenName = getSelectedScreenName();
  233.       if (screenName && (screenName != null)) {
  234.     if (isedit == 1) 
  235.           window.openDialog('chrome://aim/content/AimBuddyAlert.xul','_blank','chrome,all,dialog=no', screenName, 1);
  236.     else
  237.        window.openDialog('chrome://aim/content/AimBuddyAlert.xul','_blank','chrome,all,dialog=no', screenName, null);
  238.      }    
  239.     },
  240.     
  241.     cmdContextDelBuddyAlert : function () {
  242.       var screenName = getSelectedScreenName();
  243.       if (screenName && (screenName != null))
  244.         aimBuddyManager().DeleteBuddyFromAlertList(screenName);
  245.     },
  246.  
  247.  
  248.     //cmdContextEditAB : function () {
  249.       //dump("Context: Edit AddressBook\n");
  250.       //cmdAbEditCard();
  251.     //},     
  252.  
  253.     // Utilities
  254.  
  255.     // Show/hide one item (specified via name or the item element itself).
  256.     showItem : function ( itemOrId, show ) {
  257.         var item = null;
  258.         if ( itemOrId.constructor == String ) {
  259.             // Argument specifies item id.
  260.             item = document.getElementById( itemOrId );
  261.         } else {
  262.             // Argument is the item itself.
  263.             item = itemOrId;
  264.         }
  265.         if ( item ) {
  266.             var styleIn = item.getAttribute( "style" );
  267.             var styleOut = styleIn;
  268.             if ( show ) {
  269.                 // Remove style="display:none;".
  270.                 styleOut = styleOut.replace( "display:none;", "" );
  271.  
  272.             } else {
  273.                 // Set style="display:none;".
  274.                 if ( styleOut.indexOf( "display:none;" ) == -1 ) {
  275.                     // Add style the first time we need to.
  276.                     styleOut += "display:none;";
  277.                 }
  278.             }
  279.             // Only set style if it's different.
  280.             if ( styleIn != styleOut ) {
  281.                 item.setAttribute( "style", styleOut );
  282.             }
  283.         }
  284.     },
  285.  
  286.     // Set given attribute of specified context-menu item.  If the
  287.     // value is null, then it removes the attribute (which works
  288.     // nicely for the disabled attribute).
  289.     setItemAttr : function ( id, attr, val ) {
  290.         var elem = document.getElementById( id );
  291.         if ( elem ) {
  292.             if ( val == null ) {
  293.                 // null indicates attr should be removed.
  294.                 elem.removeAttribute( attr );
  295.             } else {
  296.                 // Set attr=val.
  297.                 elem.setAttribute( attr, val );
  298.             }
  299.         }
  300.     },
  301.  
  302.     // Set context menu attribute according to like attribute of another node
  303.     // (such as a broadcaster).
  304.     setItemAttrFromNode : function ( item_id, attr, other_id ) {
  305.         var elem = document.getElementById( other_id );
  306.         if ( elem && elem.getAttribute( attr ) == "true" ) {
  307.             this.setItemAttr( item_id, attr, "true" );
  308.         } else {
  309.             this.setItemAttr( item_id, attr, null );
  310.         }
  311.     }
  312. };
  313.